#include <bitset>
#include <cstdint>
#include <iostream>
#include <istream>
#include <map>
#include <string>
using ll = int64_t;
#define sl static inline

std::string s;
std::bitset<256> mcj,maj;
sl ll cj(){return mcj.count();}
sl ll aj(){return maj.count();}

sl void solve(){
    ll ans=0;
    mcj.reset();
    maj.reset();
    std::cin>>s;
    for(ll alen=1;alen<s.size()-1;alen++){
        maj[s[alen-1]]=maj[s[alen-1]]^1;
        for(ll blen=1;alen+blen<s.size();blen++){
            for(ll l=1;l*(alen+blen)<s.size();l++){
                mcj.reset();
                for(ll ci=l*(alen+blen);ci<s.size();ci++){
                    mcj[s[ci]]=mcj[s[ci]]^1;
                }
                if(aj()>cj()){
                    continue;
                }
                for(ll i=alen+blen;i<l*(alen+blen);i++){
                    if(s[i%(alen+blen)]!=s[i]){
                        goto nxt;
                    }
                }
                ans++;
                nxt:;
            }
        }
    }
    std::cout<<ans<<"\n";
}

int main(){
    std::iostream::sync_with_stdio(false);
    std::cin.tie(nullptr);

    ll t;
    std::cin>>t;
    while(t--){
        solve();
    }
}